var canPartition = function(nums) {
  const len = nums.length;
  const total = nums.reduce((acc, val) => acc + val, 0);
  if (total % 2 !== 0) return false;
  const target = total / 2;

  const dp = new Array(target + 1).fill(0);

  for (let i = 0; i < len; i++) {
    for (let j = target; j >= nums[i]; j--) {
      dp[j] = Math.max(dp[j], dp[j - nums[i]] + nums[i]);
    }
  }

  if (dp[target] === target) return true;

};

let nums = [1,5,11,5];
console.log(canPartition(nums)); // true